﻿using System.Collections.Generic;

namespace PluginDB
{

    public class DBManager
    {
        #region Private Members
        private readonly PluginDbEntities _pluginDbEntities;
        private readonly MoviesRepository _moviesRepository;
        private readonly TVShowsRepository _tvShowsRepository;
        private readonly CommonRepository _commonRepository;
        #endregion

        #region Ctor
        public DBManager()
        {
            _pluginDbEntities = new PluginDbEntities();
            _moviesRepository = new MoviesRepository(_pluginDbEntities);
            _tvShowsRepository = new TVShowsRepository(_pluginDbEntities);
            _commonRepository = new CommonRepository(_pluginDbEntities);
        }
        #endregion

        public void AddVideo(PluginVideoInfo pluginVideoInfo)
        {
            if (pluginVideoInfo.IsTVShow)
            {
                this._tvShowsRepository.AddTVShow(pluginVideoInfo);
            }
            else
            {
                this._moviesRepository.AddMovie(pluginVideoInfo);
            }
        }

        public List<Category> GetCategoriesList()
        {
            return _commonRepository.GetCategoriesList();
        }

        public List<Video> GetLatestMoviesList()
        {
            return _moviesRepository.GetLatestVideosList();
        }

        public List<TVShow> GetLatestTVShowsList()
        {
            return _tvShowsRepository.GetLatestVideosList();
        }

        public List<Video> GetHebSubMovies()
        {
            return _moviesRepository.GetHebSubVideos();
        }

        public List<Series> GetHebSubTVShows()
        {
            return _tvShowsRepository.GetHebSubVideos();
        }

        public bool IsMovieExists(string pluginUrl)
        {
            return _moviesRepository.IsMovieExists(pluginUrl);
        }

        public bool IsTVShowExists(string pluginUrl)
        {
            return _tvShowsRepository.IsTVShowExists(pluginUrl);
        }

        public bool IsSeriesExists(string seriesName)
        {
            return _tvShowsRepository.IsSeriesExists(seriesName);
        }

        public List<Site> GetSitesNames()
        {
            return _commonRepository.GetSitesNames();
        }

        public List<Video> GetMoviesByCategoryId(long categoryId)
        {
            return _moviesRepository.GetMoviesByCategoryId(categoryId);
        }

        public List<TVShow> GetTVShowsByCategoryId(long categoryId)
        {
            return _tvShowsRepository.GetTVShowsByCategoryId(categoryId);
        }

        public List<Video> GetHebDubMovies()
        {
            return _moviesRepository.GetHebDubVideos();
        }

        public List<Video> GetAtoZMoviesList(string startWord)
        {
            return _moviesRepository.GetAtoZMoviesList(startWord);
        }

        public List<Series> GetAtoZSeriesList(string startWord)
        {
            return _tvShowsRepository.GetAtoZSeriesList(startWord);
        }

        public List<Video> GetMoviesBySite(long siteId)
        {
            return _moviesRepository.GetMoviesBySite(siteId);
        }

        public List<Series> GetTVShowsBySite(long siteId)
        {
            return _tvShowsRepository.GetTVShowsBySite(siteId);
        }

        public Video GetMovieByID(long videoId)
        {
            return _moviesRepository.GetMovieByID(videoId);
        }

        public TVShow GetTVShowByID(long videoId)
        {
            return _tvShowsRepository.GetTVShowByID(videoId);
        }

        public VideosLink GetVideoLinkByID(long linkId)
        {
            return _moviesRepository.GetVideoLinkByID(linkId);
        }

        public TVShowsLink GetTVShowLinkByID(long linkId)
        {
            return _tvShowsRepository.GetTVShowLinkByID(linkId);
        }

        public List<Series> GetSeriesList()
        {
            return _tvShowsRepository.GetSeriesList();
        }

        public List<TVShow> GetTVShowsBySeries(long seriesId)
        {
            return _tvShowsRepository.GetTVShowsBySeries(seriesId);
        }

        public List<long> GetHebSubSeasonsbySeriesId(long seriesId)
        {
            return _tvShowsRepository.GetHebSubSeasonsbySeriesId(seriesId);
        }

        public List<long> GetSeasonsbySeriesAndSiteId(long siteId, long seriesId)
        {
            return _tvShowsRepository.GetSeasonsbySeriesAndSiteId(siteId, seriesId);
        }

        public List<long> GetSeasonsbySeriesId(long seriesId)
        {
            return _tvShowsRepository.GetSeasonsbySeriesId(seriesId);
        }

        public List<TVShow> GetHebSubTVShowsBySeasonId(long seriesId, long seasonNumber)
        {
            return _tvShowsRepository.GetHebSubTVShowsBySeasonId(seriesId, seasonNumber);
        }

        public List<TVShow> GetTVShowsBySeasonAndSiteId(long siteId, long seriesId, long seasonNumber)
        {
            return _tvShowsRepository.GetTVShowsBySeasonAndSiteId(siteId, seriesId, seasonNumber);
        }

        public List<TVShow> GetTVShowsBySeasonId(long seriesId, long seasonNumber)
        {
            return _tvShowsRepository.GetTVShowsBySeasonId(seriesId, seasonNumber);
        }

        public void InsertMegaVideoCookie(string cookieCode, System.DateTime expiredDate)
        {
            _commonRepository.InsertMegaVideoCookie(cookieCode, expiredDate);
        }

        public List<Video> GetMoviesBySearchText(string searchText)
        {
            return _moviesRepository.GetMoviesBySearchText(searchText);
        }

        public List<Series> GetTVShowsBySearchText(string searchText)
        {
            return _tvShowsRepository.GetTVShowsBySearchText(searchText);
        }
    }
}
